#include "../../maininclude.h" // 假设这是你项目中必要的头文件引用
using namespace std;

class Solution {
public:
    unordered_map<char,int> num_map;  
    unordered_map<char,bool>bool_map;  
    deque<char> q;

    void init_map(const string& t)
    {
        for(auto i : t)
        {
            num_map[i]++;
            bool_map[i] = true;
        }
    }

    bool check(const string& t)
    {
        for(auto i : t)
        {
            if(num_map[i] > 0)  return false;
        }
        return true;
    }

    string getValue(const deque<char>& q)
    {
        string result;
        deque<char> copy = q; // make a copy to avoid modifying the original queue
        while (!copy.empty()) 
        {
            result += copy.front();
            copy.pop_front();
        }
        return result;
    }

    string minWindow(string s, string t) {
        if(s == t) return s;
        int n = s.size(), m = t.size();
        if(n < m)  return "";
        string res = "";
        int min_len = INT_MAX;
        init_map(t);
        for(int i = 0; i < m; ++i)
        {
            if(bool_map[s[i]]) num_map[s[i]]--;
            q.push_back(s[i]);
        }
        int l = 0, r = m - 1;
        while(r < n)
        {
            if(check(t))
            {
                while(bool_map[s[l]] == false || num_map[s[l]] < 0)
                {
                    q.pop_front();
                    num_map[s[l]]++;
                    l++;
                }
                if(q.size() < min_len)
                {
                    res = getValue(q);
                    min_len = q.size();
                }
            }
            if(r + 1 < n)
            {
                q.push_back(s[++r]);
                if(bool_map[s[r]]) num_map[s[r]]--;
            }
            else break;
        }
        return res;
    }
};
int main()
{
    Solution s;
    string result = s.minWindow("ADOBECODEBANC", "ABC");
    cout << result << endl;
    return 0;
}